﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tender.Tool.View
{
    public partial class SqlUserControl : UserControl
    {
        public SqlUserControl()
        {
            InitializeComponent();
            uiTextBox1.Multiline = true;
            uiTextBox1.WordWarp = true;
            uiTextBox1.Text= ConfigurationManager.AppSettings["T-SQL"];
        }

        public Func<string, object> action { get; set; }
        private string selectedtext_;

        public string selectedtext
        {
            get { 
                
                return uiTextBox1.SelectedText;
            }
            set { selectedtext_ = value; }
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.AppSettings.Settings["T-SQL"].Value = uiTextBox1.Text;
            config.Save(ConfigurationSaveMode.Modified);
            uiDataGridView1.DataSource= action?.Invoke(selectedtext.Trim());
        }

        private void uiDataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }
    }
}
